<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>登录</title>
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />

</head>

<body style="background:#fff">

    <header class="aui-bar aui-bar-nav aui-bar-light" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="api.closeWin();">
            <span class="aui-iconfont aui-icon-left" style="color:#ff4280"></span>
        </a>

        <a class="aui-pull-right" tapmode onclick="fnOpenRegisterWin();">
            <span style="color:#ff4280">注册</span>
        </a>
    </header>

    <div style="padding:1rem 0;">
        <h3 style="margin:1rem 1.5rem;text-align:center;font-size:1.2rem;color:#ff4285;">用户登录</h3>
        <p style="margin:1rem;"><input type="text" placeholder="请输入手机号/账号" id="username" style="border-radius:0.5rem;border:1px solid #ccc;text-align:center"></p>
        <p style="margin:1rem;"><input type="password" placeholder="请输入密码" id="password" style="border-radius:0.5rem;border:1px solid #ccc;text-align:center"></p>
        <p style="margin:1rem;border-radius:0.5rem;border:1px solid #ccc;text-align:center;line-height:2rem;background:#ff4285;color:#fff;" onclick="fnLoginIn();"> 登录</p>
        <p style="margin:1rem;text-align:right;line-height:1rem;color:#ff4285;" onclick="fnRePassword()"> 忘记密码?&nbsp;&nbsp;&nbsp;&nbsp;</p>
    </div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript">
    apiready = function() {
        var header = $api.byId('header'); //获取节点
        $api.fixStatusBar($api.dom('header'));
        api.setStatusBarStyle({
            style: 'dark',
            color: 'transparent'
        });
        var ajpush = api.require('ajpush');
        if (api.systemType == "android") {
            ajpush.init(function(ret) {
                var param = {
                    alias: 'user1',
                    tags: ['user']
                };
                ajpush.bindAliasAndTags(param, function(ret) {});
                ajpush.setListener(jpushListener);
            });
        } else if (api.systemType == "ios") {
            ajpush.setListener(jpushListener);
            var param = {
                alias: 'user2',
                tags: ['user']
            };
            ajpush.bindAliasAndTags(param, function(ret) {});
        }
        //获取用户的设备id，上传到服务器；
        ajpush.getRegistrationId(function(ret) {
            registrationId = ret.id;

        });

        function jpushListener(ret) {}
    }


    function fnLoginIn() {

        var username = $("#username").val();
        var password = $("#password").val();
        if (typeof(registrationId) == "undefined") {
            registrationId = "";
        }
        api.ajax({
            url: SITE_URL + 'index.php?m=api&c=appnew&a=login',
            method: 'POST',
            data: {
                values: {
                    "username": username,
                    "password": password,
                    "registration_id": registrationId
                }
            }
        }, function(ret, err) {

            //判断是否登录
            //ret.status == 1
            if (ret.status == 1) {
                $api.setStorage('userInfo', ret.data);
                //登录成功后，绑定淘宝账号个数存入app
                //fnGetBindTaobaoNumber(ret.data);

                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'middle'
                });

                api.openWin({
                    name: "person_center",
                    url: "./person_center.html",
                    opaque: true,
                    vScrollBarEnabled: false,
                    reload: true
                });
                api.execScript({
                    name: 'person_center',
                    frameName: 'person_center_frame',
                    script: 'fnGetUserInfo(); '
                });
                return false;
                // api.alert({
                //     title: '提示',
                //     msg: '登录成功',
                // }, function(ret, err) {
                //     if (ret) {
                //         api.openWin({
                //             name: "person_center",
                //             url: "./person_center.html",
                //             opaque: true,
                //             vScrollBarEnabled: false,
                //             reload: true
                //         });
                //         api.execScript({
                //             name: 'person_center',
                //             frameName: 'person_center_frame',
                //             script: '  fnGetUserInfo(); '
                //         });
                //
                //     } else {
                //         alert(JSON.stringify(err));
                //     }
                // });

                //登录成功后，给数据写道app中

                //然后跳转页面

            } else {
                api.toast({
                    msg: ret.msg,
                    duration: 2000,
                    location: 'middle'
                });

            }
        });
    }
    //登录成功之后判断绑定淘宝账号的个数 如果
    function fnOpenRegisterWin() {
        api.openWin({
            name: 'register',
            url: './register.html',
            pageParam: {
                name: 'test'
            }
        });
    }

    function fnRePassword() {
        api.openWin({
            name: 're_password',
            url: './re_password.html',
            pageParam: {
                name: 'test'
            }
        });
    }
</script>

</html>
<!-- <script type="text/javascript" src="../script/api.js" ></script>
<script type="text/javascript" src="./conf/config.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script type="text/javascript">
apiready = function() {
    var header = $api.byId('header');//获取节点

    var headerH = $api.offset(header).h;//获取header的高
    api.openFrame({//打开一个frame
        name: 'login_frame',
        url: './login_frame.html',
        rect: {//定位下面
            x: 0,
            y: headerH,
            w: 'auto',
            h: 'auto'
        },
        pageParam: {//需要传到下个页面的参数
            name: 'test'
        },
        bounces: true//弹跳开启
    });
};

function fnOpenRegisterWin () {
    api.openWin({
        name: 'register',
        url: './register.html',
        pageParam: {
            name: 'test'
        }
    });
}
</script>
</html> -->
